

from PyQt4 import QtCore , QtGui


lista = ['aa', 'ab', 'ac']
listb = ['ba', 'bb', 'bc']
listc = ['ca', 'cb', 'cc']
mystruct = {'A':lista, 'B':listb, 'C':listc}

class test(QtGui.QMainWindow):
    def __init__(self , parent = None):
        QtGui.QMainWindow.__init__( self , parent)
        self.tableWidget = QtGui.QTableWidget(self) 
        self.tableWidget.setColumnCount(3)
        self.tableWidget.setRowCount(3)  
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(0, 0, item)
        self.tableWidget.item(0, 0).setText("1")
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(0, 1, item)
        self.tableWidget.item(0, 1).setText("2")
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(0, 2, item)
        self.tableWidget.item(0, 2).setText("3")
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(1, 0, item)
        self.tableWidget.item(1, 0).setText("4")
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(1, 1, item)
        self.tableWidget.item(1, 1).setText("5")
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(1, 2, item)
        self.tableWidget.item(1, 2).setText("6")
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(2, 0, item)
        self.tableWidget.item(2, 0).setText("7")
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(2, 1, item)
        self.tableWidget.item(2, 1).setText("8")
        item = QtGui.QTableWidgetItem()
        self.tableWidget.setItem(2, 2, item)
        self.tableWidget.item(2, 2).setText("9")
        self.centralwidget = QtGui.QWidget(self)
        self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout.addWidget(self.tableWidget)
        self.setCentralWidget(self.centralwidget)
        self.resize(640, 480)
        self.show()

class tableDelegate(QtGui.QStyledItemDelegate):    
    def __init__(self , parent = None ):
        super(tableDelegate ,self ).__init__( parent )
        self.parent = parent

    def createEditor(self, parent, option, index):
        if index.column() :
            self.table = QtGui.QTableView(parent)   
            self.strdTable = QtGui.QStandardItemModel(3,4)
            self.table.setModel( self.strdTable )
            self.strdTable.setData(self.strdTable.index( 0 , 0 ) , QtCore.QVariant( 'test' ) )
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(0, 0, item)
#            self.tableWidget.item(0, 0).setText("1")
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(0, 1, item)
#            self.tableWidget.item(0, 1).setText("2")
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(0, 2, item)
#            self.tableWidget.item(0, 2).setText("3")
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(1, 0, item)
#            self.tableWidget.item(1, 0).setText("4")
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(1, 1, item)
#            self.tableWidget.item(1, 1).setText("5")
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(1, 2, item)
#            self.tableWidget.item(1, 2).setText("6")
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(2, 0, item)
#            self.tableWidget.item(2, 0).setText("7")
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(2, 1, item)
#            self.tableWidget.item(2, 1).setText("8")
#            item = QtGui.QTableWidgetItem()
#            self.tableWidget.setItem(2, 2, item)
#            self.tableWidget.item(2, 2).setText("9")
        return self.table
                                             
    def setModelData(self, editor, model, index):        
        if index.column() :
            model.setData(index, QtCore.QVariant(editor.currentText())) 

    def setEditorData(self, editor, index):
        text = index.model().data(index, QtCore.Qt.DisplayRole).toString()
        i = editor.findText(text)
        if i == -1:
            i = 0
        editor.setCurrentIndex(i)

#class testDelegate(QtGui.QStyledItemDelegate):    
#    def __init__(self , parent = None ):
#        super(testDelegate ,self ).__init__( parent )
#        self.parent = parent
#
#    def createEditor(self, parent, option, index):        
#        combo = QtGui.QSpinBox(parent)
#        return combo
#    def setModelData(self, editor, model, index):        
#        editor.interpretText()
#        value = editor.value()
#
#        model.setData(index, value, QtCore.Qt.EditRole)
#            
#    def setEditorData(self, editor, index):
#        value = index.model().data(index, QtCore.Qt.EditRole)
#        editor.setValue(value)
                    
class myTree(QtGui.QMainWindow):
    def __init__( self , parent=None ):
        QtGui.QMainWindow.__init__( self , parent)
        model = QtGui.QStandardItemModel(4, 2)
#        tableView = QtGui.QTableView( self )
#        tableView.setModel(model)
#    
#        delegate = tableDelegate()
#        tableView.setItemDelegate(delegate)    
#        for row in range(4):
#            for column in range(2):
#                index = model.index(row, column, QtCore.QModelIndex())
#                model.setData(index, (row + 1) * (column + 1))
        
        
        tree = QtGui.QTreeView(self)
        tree.setModel(model)
        delegate = tableDelegate( self )
        tree.setItemDelegate(delegate)
        tree.setGeometry(QtCore.QRect(1,1 , 400 ,200) )
        tree.setUniformRowHeights(0)
        for row in range(4):
            for column in range(2):
                index = model.index(row, column, QtCore.QModelIndex())
                model.setData(index, (row + 1) * (column + 1))
#        cetralwidget = QtGui.QWidget(self)
#        self.treeWidget = QtGui.QTreeWidget(self)
#        self.treeWidget = QtGui.QTreeView(self)
#        self.treeWidget.setModel(model)
#        self.treeWidget.setGeometry(QtCore.QRect(1,1 , 400 ,200) )
#        self.treeWidget.setItemDelegateForColumn (0, tableDelegate(self) )
#        self.treeWidget.headerItem().setText(0, QtCore.QString("Asset Name"))        
#        item_0 = QtGui.QTreeWidgetItem(self.treeWidget)
#        item_1 = QtGui.QTreeWidgetItem(item_0)
#        self.treeWidget.topLevelItem(0).setText(0,QtCore.QString('asset1') )
#        item_2 = QtGui.QTreeWidgetItem(item_1)
#        item_0 = QtGui.QTreeWidgetItem(self.treeWidget)        
#        self.treeWidget.topLevelItem(1).setText(0,QtCore.QString('asset2') )
#        self.treeWidget.topLevelItem(0).setText(QtCore.QString('asset1') )
        self.resize(640, 480)
        self.show()
               

if __name__ == '__main__':
    import sys    
    app = QtGui.QApplication(sys.argv)
    ui = myTree()  
#    ui = test()  
    app.exec_() 